﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Data.Common;
using ST.DAL;
using ST.Model;

namespace ST.BLL
{
    /// <summary>
    /// 管理员的数据库相关操作
    /// </summary>
    public class AdminService
    {

        static SqlServerDBHelper db = null;
        public AdminService()
        {
            db = new SqlServerDBHelper();
        }
        public AdminInfo Login(string name, string pass)
        {
            string sql = string.Format(@"select * from UserInfo 
where UserName='{0}' and UserPwd='{1}'", name,pass);
            AdminInfo admin = null;
            DbDataReader dr = db.GetReader(sql);
            if (dr.Read())//判断是否查询到数据
            {
                admin = new AdminInfo();
                admin.UserId = Convert.ToInt32(dr["UserId"]);
                admin.UserName = dr["UserName"].ToString();
                admin.UserPwd = dr["UserPwd"].ToString();
                admin.State = Convert.ToInt32(dr["State"]);
            }
            dr.Close();
            db.Close();

            return admin;
        }
    }
}
